package com.pro01.apirednote.controller;

import com.pro01.apirednote.pojo.Result;
import com.pro01.apirednote.service.ContentLikeService;
import com.pro01.apirednote.service.ContentService;
import com.pro01.apirednote.utils.TokenUtil;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/contents")
@RequiredArgsConstructor
public class ContentLikeController {

    private final ContentLikeService contentLikeService;

    private final ContentService contentService;

    // 点赞/取消点赞
    @PostMapping("/{contentId}/like-switch")
    public Result<Boolean> toggleLike(@PathVariable Long contentId, HttpServletRequest request) {
        Long userId = TokenUtil.getUserId(request);
        return contentLikeService.toggleLike(userId, contentId);
    }

    // 用户是否点赞了当前帖子
    @GetMapping("/{contentId}/like-status")
    public Result<Boolean> getLikeStatus(@PathVariable Long contentId, HttpServletRequest request) {
        Long userId = TokenUtil.getUserId(request);
        return contentLikeService.hasLiked(userId, contentId);
    }
}